<!-- 组织工作地点控件 -->

<template>
  <a-space direction="vertical" style="width: 100%">
    <a-select
      allow-search
      :placeholder="getProps.placeholder"
      :disabled="disabled"
      @change="select"
      v-model="currData"
      ref="selectRef"
    >
      <a-option
        v-for="item in list"
        :value="item.id"
        :label="item.name"
        :key="item.id"
      ></a-option>
    </a-select>
  </a-space>
</template>

<script lang="ts" setup>
import { GetWorkPlaceList } from '@/apis/management/organization/organizationManagement';

const props = withDefaults(
  defineProps<{
    props: { [propName: string]: any };
    name?: string;
    required?: boolean;
    disabled?: boolean;
    oneValue: any;
    regex?: {
      [name: string]: {
        role: any;
        name: any;
      };
    };
  }>(),
  {}
);

const emit = defineEmits(['update:oneValue']);

let currData = ref();
const modelValue = computed({
  get: () => {
    return props.oneValue;
  },
  set: (val) => {
    emit('update:oneValue', val);
  }
});

onMounted(() => {
  currData.value = Number(modelValue.value);
});
//复制一份props
const getProps = computed(() => {
  return props.props;
});

let selectRef = ref();

let list = ref();

// 获取数据
const getData = async () => {
  try {
    const { content } = await GetWorkPlaceList({
      page: 1,
      size: -1
    });
    list.value = content;
  } catch (error: unknown) {
    console.log(error);
  }
};
getData();

const select = () => {
  nextTick(() => {
    modelValue.value = selectRef.value.$el.nextElementSibling.innerText;
  });
};
</script>

<style scoped lang="less"></style>
